package com.example.demo.controller;


import com.auth0.jwt.interfaces.DecodedJWT;
import com.example.demo.entity.Menu;
import com.example.demo.entity.Result;
import com.example.demo.pojo.User;
import com.example.demo.service.LoginService;
import com.example.demo.service.MenuService;
import com.example.demo.service.UserService;
import com.example.demo.utils.JWTUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class LoginController {
    @Autowired
    private LoginService loginService;
    @Autowired
    private MenuService menuService;
    @Autowired
    private UserService userService;
    /**
     * 登录接口
     * @param user
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody User user,HttpServletRequest request){
        return loginService.login(user);
    }

    /*
     * 注册
     * */
    @PostMapping("/register")
    public Result editContr(MultipartFile[] file, @RequestParam Map<String,Object> paramMap, HttpServletRequest request){
        return userService.register(file,paramMap,request);
    }
    /**
     * 退出登录
     * @return
     */
    @PostMapping("/logout")
    public Result logout(){
        return loginService.logout();
    }

    /**
     * 验证Token
     */
    @GetMapping("checkToken")
    public Result checkToken(HttpServletRequest request){
        return loginService.checkToken(request);
    }
}
